//
//  NoteDB.m
//  geoNotes
//
//  Created by Administrator on 6/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NoteDB.h"


@implementation NoteDB
-(id)init{
    self=[super init];
    if(self)
    {
       noteDB= [[NSMutableArray alloc] init]; 
    }
    return self;
}
-(NSMutableArray*) database{
    return [[noteDB copy] autorelease];
}
-(Note*) noteAtPosition:(NSUInteger)pos{
    return [noteDB objectAtIndex:pos]; 
}
-(NSUInteger) notesInDB{
    return [noteDB count];
}
-(void) addNoteToDB:(Note*) note{
    //NSLog(@"add note: %@",[note description]);
    [noteDB addObject:note];
}
-(void)deleteNote:(Note *)note{
    [noteDB removeObject:note];
}
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:noteDB forKey:@"NoteDB"];
}
- (id)initWithCoder:(NSCoder *)aDecoder{
    self=[super init];
    if(self){
       noteDB= [[aDecoder decodeObjectForKey:@"NoteDB"] retain];
       //NSLog(@"%@",[noteDB description]);
    }
    return self;
}
-(NSString *)description{
    NSString* desc= [NSString stringWithString:@"NoteDB contains:\n"];
    for (Note *note in noteDB) {
        desc=[desc stringByAppendingString:[note description]];
    }
    return desc;
}
@end
